using System.Collections;
using UnityEngine;

namespace WorkFlow.Net
{
    public class EnumeratorRunner : MonoBehaviour
    {
        static EnumeratorRunner _instance;

        public static EnumeratorRunner Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new GameObject("EnumeratorRunner").AddComponent<EnumeratorRunner>();
                    DontDestroyOnLoad(_instance.gameObject);
                }
                return _instance;
            }
        }

        private void Awake()
        {
            if (_instance == null)
            {
                _instance = this;
                DontDestroyOnLoad(gameObject);
            }
            else
            {
                Destroy(gameObject);
            }
        }
        
        public Coroutine Run(IEnumerator enumerator)
        {
            return StartCoroutine(enumerator);
        }
    }
}

